// ActionScript file
/*
* 航班控制的接口
*/
import mx.rpc.events.ResultEvent;

//获取机场数据                                 			
private function initUI():void
{	
	FlightService.getOperation('getAirport').send();
}

//传递到控件			
private function getAirportHandler(evt:ResultEvent):void
{	
	startList.dataProvider = evt.result;
	endList.dataProvider = evt.result;
}

//注册事件		
private function addUserHandler(evt:ResultEvent):void
{	
	if( evt.result=='true' )
		Alert.show('注册成功,点击确定跳转到登录窗口','注册成功',Alert.YES,this,alertHandler,null,Alert.YES);
	else if(evt.result=='falsenull')
		Alert.show('注册失败，必选项不能为空');
	else if(evt.result=='falsepw')
		Alert.show('注册失败，密码为6-10位');	
	else if(evt.result=='falsemail')
		Alert.show('注册失败，请输入正确的邮箱');			
	else if(evt.result=='falseexist')
		Alert.show('注册失败，用户名被占用');			
	else if(evt.result=='falsesave')
		Alert.show('注册失败，请重新注册，或者检查网络是否连通');				
}

//响应获取航班事件，并修改控件		
private function getResultHandler( evt:ResultEvent ):void
{	
	flightList.dataProvider = evt.result;
}

private function getResultAllHandler( evt:ResultEvent ):void
{	
	flightList0.dataProvider = evt.result;
}

//获取所有航班，并修改控件	
private function getResultHandler0( evt:ResultEvent ):void
{	
	flightList0.dataProvider = evt.result;
}
			
//选择的航班序号
private var flightId:String;

//获取航班座位信息
private function getFlightInfoHandler( evt:ResultEvent ):void
{
	flightId = evt.result.toString();
	
	MService.getOperation('getRemainseat').send( flightId );				
}

private function getFlightInfo1Handler( evt:ResultEvent ):void
{
	backToFlight2();
	flightId1.text = evt.result.flight.toString();
	date1.text = evt.result.date.toString();
	planeId1.text = evt.result.plane.toString();
	start1.text = evt.result.start.toString();
	end1.text = evt.result.end.toString();
	startTime1.text = evt.result.start_time.toString();
	endTime1.text = evt.result.end_time.toString();
	firstSeat1.text = evt.result.first_class.toString();
	firstPrice1.text = evt.result.fprice.toString();
	secondSeat1.text = evt.result.second_class.toString();
	secondPrice1.text = evt.result.sprice.toString();
	thirdSeat1.text = evt.result.third_class.toString();
	thirdPrice1.text = evt.result.tprice.toString();	
	booked1 = evt.result.booked.toString();			
}

private function init():void{
		
		flightId1.text = "";
		date1.text ="";
		planeId1.text ="";
		start1.text = "";
		end1.text = "";
		startTime1.text = "";
		endTime1.text = "";
		firstSeat1.text = "";
		firstPrice1.text ="";
		secondSeat1.text = "";
		secondPrice1.text = "";
		thirdSeat1.text = "";
		thirdPrice1.text = "";
		booked1.text ="";
}
private function getDelFlightHandler(evt:ResultEvent):void
{
	if(evt.result){
		Alert.show('删除成功','删除成功');
		flightId1.text = "";
		date1.text ="";
		planeId1.text ="";
		start1.text = "";
		end1.text = "";
		startTime1.text = "";
		endTime1.text = "";
		firstSeat1.text = "";
		firstPrice1.text ="";
		secondSeat1.text = "";
		secondPrice1.text = "";
		thirdSeat1.text = "";
		thirdPrice1.text = "";
		booked1.text="";
	}
	else
		Alert.show('删除失败,航班不存在','删除失败');
}
			
//剩余座位
private var remainSeat:Array = new Array();

///获取剩余座位信息		
private function getRemainseatHandler( evt:ResultEvent ):void
{
	currentState="seat";
	remainSeat = evt.result as Array;
	seatList.dataProvider = remainSeat;						
}
			
//触发列表单击事件
private function getSeat(event:Event):void
{
    FlightService.getOperation('getFlightInfo').send( flightList.selectedItem.id );
}

private function getInfo(event:Event):void
{
    FlightService.getOperation('getFlightInfo1').send( flightList0.selectedItem.id );
}


//处理提交订票信息的返回信息
private function orderTicketsHandler( evt:ResultEvent ):void
{
	CursorManager.removeBusyCursor();
	if( evt.result )
		Alert.show('订票成功,点击确定跳转到主页面','订票成功',Alert.YES,this,alertHandler,null,Alert.YES);
	else
		Alert.show('订票失败，请重新选择，或者检查网络是否连通');
}

//提交订票信息
private function order():void
{
	var seat:Array = seatList.selectedItems; //获取选择的座位
	var ix:int = 0;
	var seatStr:String = null; //存储整合的字符串
	var quantity:int = seat.length; //座位个数
	for( ix = 0 ; ix < quantity; ix++ )
	{
		if( seatStr == null )
			seatStr = seat[ix]['label'];
		else
			seatStr = seatStr + "," + seat[ix]['label'];	
	}
	FlightService.getOperation('orderTickets').send( flightId, userId, seatStr, quantity  );
}